package top.huhuiyu.myforum.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import top.huhuiyu.myforum.entity.TbReturns;
import top.huhuiyu.myforum.model.TbReturnsModel;
import top.huhuiyu.myforum.dao.TbReturnsDAO;
import top.huhuiyu.myforum.util.JsonMessage;

/**
 * TbReturns的控制器类
 */
@RestController
@RequestMapping("/tbReturns")
public class TbReturnsController {
  
  @Autowired
  private TbReturnsDAO tbReturnsDAO;
  
  @RequestMapping("/save")
  public JsonMessage save(TbReturnsModel tbReturnsModel) throws Exception {
    // 测试模板 /tbReturns/save {"tbReturns.iid":"1","tbReturns.uid":"2","tbReturns.content":"3","tbReturns.created":"4"}
    tbReturnsDAO.save(tbReturnsModel.getTbReturns());
    return JsonMessage.getSuccessMessage("数据保存成功");
  }
  
  @RequestMapping("/update")
  public JsonMessage update(TbReturnsModel tbReturnsModel) throws Exception {
    // 测试模板 /tbReturns/update {"tbReturns.rid":"1","tbReturns.iid":"2","tbReturns.uid":"3","tbReturns.content":"4","tbReturns.created":"5"}
    tbReturnsDAO.update(tbReturnsModel.getTbReturns());
    return JsonMessage.getSuccessMessage("数据修改成功");
  }
  
  @RequestMapping("/delete")
  public JsonMessage delete(TbReturnsModel tbReturnsModel) throws Exception {
    // 测试模板 /tbReturns/delete {"tbReturns.rid":"1"}
    tbReturnsDAO.delete(tbReturnsModel.getTbReturns());
    return JsonMessage.getSuccessMessage("数据删除成功");
  }
  
  @RequestMapping("/queryByKey")
  public JsonMessage queryByKey(TbReturnsModel tbReturnsModel) throws Exception {
    // 测试模板 /tbReturns/queryByKey {"tbReturns.rid":"1"}
    TbReturns tbReturns = tbReturnsDAO.queryByKey(tbReturnsModel.getTbReturns());
    JsonMessage message = JsonMessage.getSuccessMessage("数据查询完成");
    message.putData("tbReturns",tbReturns);
    return message;
  }
  
  @RequestMapping("/queryAll")
  public JsonMessage queryAll(TbReturnsModel tbReturnsModel) throws Exception {
    // 测试模板 /tbReturns/queryAll {}
    PageHelper.startPage(tbReturnsModel.getPage().getPageNumber(), tbReturnsModel.getPage().getPageSize());
    Page<TbReturns> list = (Page<TbReturns>) tbReturnsDAO.queryAll();
    tbReturnsModel.getPage().setPageInfo(list);
    JsonMessage message = JsonMessage.getSuccessMessage("查询成功！");
    message.putData("list", list);
    message.putData("page", tbReturnsModel.getPage());
    return message;
  }
  
}
